package com.istock.state.demo.controller;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.istock.state.demo.constants.OrderInfoStatusEnum;
import com.istock.state.demo.model.OrderInfo;
import com.istock.state.demo.service.BadService;
import com.istock.state.demo.service.OrderInfoService;

@Controller
public class BadController {

	@Autowired
	private OrderInfoService orderInfoService;
	@Autowired
	private BadService badService;
	
	@RequestMapping("badAddOrder")
	public @ResponseBody Map<String , Object> badAddOrder(String name , BigDecimal amount) {
		Map<String ,Object> result = new HashMap<String , Object>();
		
		if(StringUtils.isBlank(name)) {
			result.put("message", "name不能为空");
			return result;
		}
		
		if(amount == null || amount.compareTo(BigDecimal.ZERO)<=0) {
			result.put("message", "amount不能为空");
			return result;
		}
		
		OrderInfo orderInfo = orderInfoService.createOrderInfo(name, OrderInfoStatusEnum.NO_PAY.getValue(), amount);
		return badService.handlerOrder(orderInfo);
	}
}
